crypto = require('crypto')
date_util = require('./date_util')


md5_encrypt = (text) ->
  text = text + '|GFZQ'
  md5 = crypto.createHash('md5')
  md5.update(text)
  msg = md5.digest('hex')
  return  msg.toUpperCase().substr(0,28)

exports.encode = (ids,date) ->
  time = date_util.get_full_time(date)
  result = {}
  id_arr = ids.split(',')
  if id_arr.length == 1
    params = {}
    text = time+'|'+ids
    msg = md5_encrypt(text)
    params.time = time
    params.code = msg
    result[ids] = params
  else
    for id in id_arr
      params = {}
      text = time+'|'+id
      msg = md5_encrypt(text)
      params.time = time
      params.code = msg
      result[id] = params
  return result